
/**
 房间运营状态
 *
*/
 
import { TeamDefender } from "GameLoop/WorldState/EntityManager/Entitys/team/war/TeamDefender";
 
import { State } from "framework/FSM/AState";
import { ActionArgHelper } from "../../ActionManager/ActionArgHelper";
import { PositionHelper } from "utils/position/PositionHelper";
/**
小队的执行状态
 */

export class TeamDefenderState<T extends IStateArg<TeamDefender >> extends State<T>
{
    public getActions(arg:T):Action[]
    {
        
        const room = Game.rooms[arg.entity.region];

        const task = room.findTaskById<ITask<ITeamTaskData<"defend">>>(arg.entity.getNodeMemory().bindTask);
        if(!task)
        {
            return []
        }
        const creeps = arg.entity.creeps;
        const workroom = Game.rooms[task.data.room];
        if(workroom && (task.data.arg.enemy || task.data.arg.structures))
        {   
            let target:Id<AttackObject>
            if(task.data.arg.enemy.length)
            {
                target =  task.data.arg.enemy[0];
            }
            else if(task.data.arg.structures.length)
            {
                target =  task.data.arg.structures[0];
            }
            return creeps.map(e=>
                {
                    if(e.bodyCount(ATTACK))
                    {
                        return ActionArgHelper.actionAttack(e,Game.getObjectById(target) as AttackObject,"attackRed");
                    }
                    else
                    {
                        return ActionArgHelper.actionAttack(e,Game.getObjectById(target) as AttackObject,"attackBlue")
                    }
                })
        }
        else
        {
            return  creeps.map(e=>
                {
                    return ActionArgHelper.actionMoveto(e,{pos:PositionHelper.Create({x:25,y:25,roomName:task.data.room}),range:10},{});
                })
        }

        // return [];
    }
    
}
